package com.sam4cloud.common.mybatisplus.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.sam4cloud.common.mybatisplus.plugins.MicroMetaObjectHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MybatisPlus 配置
 */
@Configuration
public class MybatisPlusAutoConfiguration {

    /**
     * 分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        PaginationInnerInterceptor pit = new PaginationInnerInterceptor();
        //设置分页最大条数
        pit.setMaxLimit(500L);
        interceptor.addInnerInterceptor(pit);
        return interceptor;
    }

    /**
     * 乐观锁插件
     */
    @Bean
    public OptimisticLockerInnerInterceptor optimisticLockerInterceptor() {
        return new OptimisticLockerInnerInterceptor();
    }


    /**
     * 字段自动填充
     */
    @Bean
    public MicroMetaObjectHandler microMetaObjectHandler() {
        return new MicroMetaObjectHandler();
    }

}
